package com.ruoyi.web.controller.analysis.meter;

import com.ruoyi.basedata.domain.MeterSheets;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.datastatistics.model.MeterConsumptionQueryModel;
import com.ruoyi.datastatistics.model.MeterConsumptionResultModel;
import com.ruoyi.datastatistics.model.MeterReadingRateResultModel;
import com.ruoyi.datastatistics.service.IMeterReadingRateService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.datastatistics.model.MeterReadingRateQueryModel;
import com.ruoyi.datastatistics.service.ITerminalsFreezeXbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/analysis/meter")
public class MeterAnalysisController extends BaseController {
    @Autowired
    private IMeterReadingRateService meterReadingRateService;

    @Autowired
    private ITerminalsFreezeXbService terminalsFreezeXbService;

    /**
     * 查询抄表率统计数据
     */
    @PreAuthorize("@ss.hasPermi('analysis:meter:readingrate')")
    @GetMapping("/getReadingRateList")
    public AjaxResult getReadingRateList(MeterReadingRateQueryModel model) {
        Map<String, Object> resultMap = meterReadingRateService.getReadingRateList(model);
        return AjaxResult.success(resultMap);
    }

    /**
     * 导出抄表率统计数据
     */
    @PreAuthorize("@ss.hasPermi('analysis:meter:readingrate')")
    @Log(title = "导出抄表率统计数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportReadingRate")
    public void exportReadingRate(HttpServletResponse response, MeterReadingRateQueryModel model) {
        model.setPageNum(1);
        model.setPageSize(999999);
        Map<String, Object> resultMap = meterReadingRateService.getReadingRateList(model);
        ExcelUtil<MeterReadingRateResultModel> util = new ExcelUtil<>(MeterReadingRateResultModel.class);
        util.exportExcel(response, (List) resultMap.get("dataRows"), "抄表率统计数据");
    }

    /**
     * 查询小用户档案列表
     */
    @PreAuthorize("@ss.hasPermi('analysis:meter:waterconsumption')")
    @GetMapping("/getWaterConsumptionList")
    public AjaxResult getWaterConsumptionList(MeterConsumptionQueryModel model) {
        Map<String, Object> resultMap = terminalsFreezeXbService.getConsumptionList(model);
        return AjaxResult.success(resultMap);
    }

    /**
     * 导出抄表率统计数据
     */
    @PreAuthorize("@ss.hasPermi('analysis:meter:readingrate')")
    @Log(title = "导出抄表率统计数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportWaterConsumption")
    public void exportReadingRate(HttpServletResponse response, MeterConsumptionQueryModel model) {
        model.setPageNum(1);
        model.setPageSize(999999);
        Map<String, Object> resultMap = terminalsFreezeXbService.getConsumptionList(model);
        ExcelUtil<MeterConsumptionResultModel> util = new ExcelUtil<>(MeterConsumptionResultModel.class);
        util.exportExcel(response, (List) resultMap.get("dataRows"), "抄表率统计数据");
    }
}
